#include<stdio.h>
#include<math.h>
int main()
{
    float fx(float(*)(float),float,float,int);
    float fsin(float);
    float fcos(float);
    float fexp(float);
    float a1,b1,a2,b2,a3,b3,c,(*p)(float);
    int n=20;//这个是划分精度，n越大精度越高
    printf("============please enter a1 and b1===========\n");
    scanf("%d %d",&a1,&b1);
    printf("============please enter a2 and b2===========\n");
    scanf("%d %d",&a2,&b2);
    printf("============please enter a3 and b3===========\n");
    scanf("%d %d",&a3,&b3);
    p=fsin;//fsin的入口地址传给p
    c=fx(p,a1,b1,n);
    printf("the integral of sin(x) is %f\n",c);
    p=fcos;
    c=fx(p,a2,b2,n);
    printf("the integral of cos(x) is %f\n",c);
    p=fexp;
    c=fx(p,a3,b3,n);
    printf("the integral of exp is %f\n",c);

}
float fx(float(*p)(float),float a,float b,int n)//此处p作为实参，把fsin的入口地址传给形式参数p
{
    int i;
    float x,h,s;
    h=(b-a)/n;//划分每个区间的大小
    x=a;
    s=0;
    for(i=1;i<=n;i++)
    {
        x=x+h;
        s=s+(*p)(x)*h;//开始累加区间的面积
    }
    return (s);

}
float fsin(float x)
{
    return sin(x);
}
float fcos(float x)
{
    return cos(x);
}
float fexp(float x)
{
    return exp(x);
}